home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14042 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.8 KB  |  106 lines

  1. Path: news.cs.columbia.edu!news-not-for-mail
  2. From: jean@news.cs.columbia.edu (Hyae-Jin Oh)
  3. Newsgroups: comp.lang.c++
  4. Subject: [HELP] ostream inheritance Q?
  5. Date: 28 Mar 1996 17:42:52 -0500
  6. Organization: Columbia University Department of Computer Science
  7. Message-ID: <4jf4lc$t8l@ground.cs.columbia.edu>
  8. NNTP-Posting-Host: ground.cs.columbia.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.  
  12.     i'm trying to come up with new output stream, say Nostream,
  13. which provides some more functionality beyond ostream as follows.
  14.  
  15. --------------------------------------------------
  16. class Nostream : public ostream {
  17. public:
  18.     Nostream(streambuf *sb) : ios(sb) {}
  19.     ~Nostream() {}
  20.  
  21.     Nostream& foo(const char *msg) {
  22.         return *this << mime;
  23.     }
  24.  
  25.     Nostream& operator << ( Nostream& (*funcPtr)(const char *msg)
  26. ) {
  27.         return (*funcPtr)(msg);
  28.     }
  29.  
  30.     .... // some more functionality...
  31. }
  32.  
  33. int main()
  34. {
  35.     Nostream nout(cout.rdbuf());
  36.  
  37.     nout << "TEST" << endl;
  38.  
  39.     nout.header("blah");    --------- 1
  40.     nout << header("blah"); --------- 2
  41. }
  42. --------------------------------------------------
  43.  
  44.     my intention of providing overloaded "<<" operator 
  45. which gets function pointer as a parameter is
  46. to use statements "1" and "2" interchangably like above
  47. with same effect.
  48.  
  49.     however, this doesn't pass through Sun Sparc 3.1 CC compiler:
  50. it generates lots of warning and one error. what am i doing wrong
  51. here? other than this error, all others are working correctly.
  52. many thanks.
  53.  
  54. (line number is bogus)
  55. --------------------------------------------------
  56. /opt/SUNWspro/bin/CC -c -g +w2  -D__SOLARIS__ -DDEBUG_ASSERT  foo.C
  57. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  58. ostream::operator<<(char).
  59. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  60. ostream::operator<<(ios&(*)(ios&)).
  61. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  62. ostream::operator<<(ostream&(*)(ostream&)).
  63. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  64. ostream::operator<<(streambuf*).
  65. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  66. ostream::operator<<(const void*).
  67. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  68. ostream::operator<<(void*).
  69. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  70. ostream::operator<<(const char*).
  71. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  72. ostream::operator<<(long double).
  73. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  74. ostream::operator<<(double).
  75. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  76. ostream::operator<<(float).
  77. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  78. ostream::operator<<(unsigned long long).
  79. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  80. ostream::operator<<(long long).
  81. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  82. ostream::operator<<(unsigned long).
  83. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  84. ostream::operator<<(long).
  85. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  86. ostream::operator<<(unsigned).
  87. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  88. ostream::operator<<(int).
  89. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  90. ostream
  91. ::operator<<(unsigned short).
  92. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  93. ostream::operator<<(short).
  94. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  95. ostream::operator<<(const wchar_t*).
  96. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  97. ostream::operator<<(wchar_t).
  98. "foo.H", line 61: Warning: Nostream::operator<< hides the function
  99. ostream::operator<<(unsigned char).
  100. "foo.C", line 38: Error: msg is not defined.    <<<--------!!!!
  101. 1 Error(s) and 23 Warning(s) detected.
  102. -- 
  103. Hyae-Jin Oh                        
  104. jean@cs.columbia.edu
  105. http://www.cs.columbia.edu/~jean/
  106.